package com.kanshu.mvp_pro.mvp;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public abstract class ActivityPresenter<D extends IActivityDelegate> extends AppCompatActivity implements IActivityPresenter<D> {

    private D mViewDelegate;

    public ActivityPresenter() {
        try {
            mViewDelegate = provideDelegateClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mViewDelegate.create(getLayoutInflater(), savedInstanceState);
        setContentView(mViewDelegate.getRootView());
        mViewDelegate.initWidget();
    }


    @Override
    public D getViewDelegate() {
        return mViewDelegate;
    }


}
